package com.spdzen.support;

import java.io.Serializable;
import java.util.List;

/**
 * 分页JSON
 * 
 * @author accontwcx@qq.com
 * @param <T> 分页返回的数据类
 */
public class SimplePage<T> implements Serializable {
	private static final long serialVersionUID = 8971662241928124095L;
	
	public static final int DEFAULT_OFFSET = 0;
	public static final int DEFAULT_PAGE_NUM = 1;
	/**
	 * 默认页面大小
	 */
	public static final int DEFAULT_PAGE_SIZE = 20;
	
	/**
	 * 数据总数
	 */
	private long total = 0;

	/**
	 * 每页数量
	 */
	private int pageSize = DEFAULT_PAGE_SIZE;

	/**
	 * 当前页数，从1开始
	 */
	private int pageNum = DEFAULT_PAGE_NUM;

	/**
	 * 当前页面数据
	 */
	private List<T> rows;

	public SimplePage() {
	}

	public SimplePage(int pageNum, int pageSize) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public int getPageCount() {
		return (total > 0 && pageSize > 0) ? (int) Math.ceil(total / pageSize) : 0;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
}
